package com.baizhi.stringx;

/**
 * String常用方法2
 */
public class StringDemo3 {
    public static void main(String[] args) {
        String str = "      HelloWorld      ";

        System.out.println(str.length());
        System.out.println(str);

        /*
         String trim();
         去掉当前字符串两端的空白
         */
        String trim = str.trim();
        System.out.println(trim);
        System.out.println(trim.length());

        /*
          char  charAt(int index)
          获取指定位置上的字符
         */
        //             0123456789
        String str2 = "HelloWorld";
        //获取H
        char c = str2.charAt(0);
        System.out.println(c);
        //获取W
        c = str2.charAt(5);
        System.out.println(c);

        /*
            boolean startsWidth(String str)
            判断当前字符串是否是以指定的字符串开始的


            boolean endsWIdth(String str)
            判断当前字符串是否是以指定的字符串结尾的
         */
        boolean he = str2.startsWith("He");
        System.out.println(he); //true

        he = str2.startsWith("he");
        System.out.println(he); //false

        boolean rld = str2.endsWith("rld");
        System.out.println(rld); //true;

        rld = str2.endsWith("m");
        System.out.println(rld);

        /*
            String toUpperCase()
            将当前字符串全部转换成大写字符

            String toLowerCase()
            将当前字符串全部转换成小写字符
         */
        String str3 = "我爱Java";
        String s = str3.toUpperCase();
        System.out.println(s);

        String s1 = str3.toLowerCase();
        System.out.println(s1);
    }
}
